<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<%@ page import="com.idp.web.test.entity.Warehouse"%>
<div class="col-md-12">
	<div class="panel-search">
		<form class="form-inline" action="/warehouse/list"></form>
		<div class="btn-div">
			<div class="div-left" style="width: 20%; height: 700px;">

				<div class="left-head">
					<label class="left-head-label1">仓库</label>
					<button class="btn btn-default"
						style="color: #4682B4; float: right; height: 30px; font-size: 15px;"
						onclick="add('/warehouse/warehouse')">新增</button>
				</div>
				<br>
				<div class="left-treebox">
					<div class="tree well"
						style="border: 3px solid #ffffff; background-color: #ffffff;">
						<c:forEach items="${warehouseType}" var="type" varStatus="status">
							<ul style="padding-left: 0px;">
								<li><span onclick="togglePic(this)"><i
										class="glyphicon glyphicon-folder-open"></i>&nbsp;${type.name}
								</span>
									<ul>
										<c:forEach items="${type.warehouseList}" var="warehouse"
											varStatus="status">

											<li><span><i
													class="glyphicon glyphicon-minus-sign"
													style="cursor: pointer;"
													onclick="deleteWarehouse(this,${warehouse.id })"></i><a
													onclick="test123('${warehouse.id }')">&nbsp;${warehouse.name}</a></span></li>
										</c:forEach>
									</ul></li>
							</ul>
						</c:forEach>
					</div>

				</div>
			</div>
			<div class="div-right" style="width: 80%; height: 700px;"></div>

		</div>
	</div>
	<div id="zzzz" class="panel-content"></div>
</div>
<style type="text/css">
.left-head {
	width: 100%;
	height: 50px;
	background-color: #4682B4;
	padding: 3%;
}

.left-head-label1 {
	color: #ffffff;
	font-size: 20px;
}

.left-treebox {
	width: 100%;
	height: 600px;
	border: 1px solid #4682B4;
}
</style>
<style>
.tree {
	min-height: 20px;
	padding: 19px;
	margin-bottom: 20px;
	background-color: #fbfbfb;
	border: 1px solid #999;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	border-radius: 4px;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
	-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
	box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05)
}

.tree li {
	list-style-type: none;
	margin: 0;
	padding: 10px 5px 0 5px;
	position: relative
}

.tree li::before, .tree li::after {
	content: '';
	left: -20px;
	position: absolute;
	right: auto
}

.tree li::before {
	border-left: 1px solid #999;
	bottom: 50px;
	height: 100%;
	top: 0;
	width: 1px
}

.tree li::after {
	border-top: 1px solid #999;
	height: 20px;
	top: 25px;
	width: 25px
}

.tree li span {
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border: 1px solid #999;
	border-radius: 5px;
	display: inline-block;
	padding: 3px 8px;
	text-decoration: none
}

.tree li.parent_li>span {
	cursor: pointer
}

.tree>ul>li::before, .tree>ul>li::after {
	border: 0
}

.tree li:last-child::before {
	height: 30px
}

.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span
	{
	background: #eee;
	border: 1px solid #94a0b4;
	color: #000
}
</style>
<script type="text/javascript">
	function test123(id) {
		$.ajax({
			type : 'post',
			url : webRoot + '/warehouse/getWarehouseInfo',
			data : {
				'id' : id
			},
			success : function(data) {
				$(".div-right").html(data);
				/* 检查该仓库是否已经都添加过物流 */
				if ($('span[name=logisticsSize]').html() == 4) {
					$('a[name=addLogistics]').css('color','red');
					$('a[name=addLogistics]').attr('onclick', 'hint("该仓库已添加了所有的邮寄方式")');
				}
			}
		});
	}
	$(function() {
		$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr(
				'title', 'Collapse this branch');
		$('.tree li.parent_li > span').on(
				'click',
				function(e) {
					var children = $(this).parent('li.parent_li').find(
							' > ul > li');
					if (children.is(":visible")) {
						children.hide('fast');
						$(this).attr('title', 'Expand this branch')
								.find(' > i').addClass('icon-plus-sign')
								.removeClass('icon-minus-sign');
					} else {
						children.show('fast');
						$(this).attr('title', 'Collapse this branch').find(
								' > i').addClass('icon-minus-sign')
								.removeClass('icon-plus-sign');
					}
					e.stopPropagation();
				});
	});

	 
	/** 更改仓库图标(open/close) */ 
	function togglePic(obj) {
		var status = $(obj).find('i:eq(0)').attr('class');
		if (status.indexOf('open') > 0) {
			$(obj).find('i:eq(0)').attr('class',
					'glyphicon glyphicon-folder-close');
		} else {
			$(obj).find('i:eq(0)').attr('class',
					'glyphicon glyphicon-folder-open');
		}
	}
	
	/** 删除仓库(id) */
	function deleteWarehouse(obj,id) {
		$.when($.ajax({
			type:'post',
			url:webRoot+"/warehouse/emptyCheck",
			data:{
				id:id
			},
			dataType:'json'
		}).done(function (data) {
			console.log(data.result);
			if(data.result == "faile") {
				alert("该仓库正在被使用不可被删除");
			} else {
				$.ajax({
					type:'post',
					url:webRoot+"/warehouse/delete",
					data:{
						id:id
					},
					dataType:'json',
					success:function(data) {
						if(data.result == "delete_success") {
							$(obj).parent().parent().remove();
							if($('#abc').find('span[name=warehouseId]').html() == id) {
								$('.div-right.data').remove();
							}
						} else{
							alert("未知错误，请重试");
						}
					}
				}) 
			}
		}))	
	}
</script>